package chapter7.homework;

// 自定义异常类
class InvalidAgeException extends Exception {
    public InvalidAgeException(String message) {
        super(message);
    }
}

// Student 类
class Student {
    private int id;
    private String name;
    private int age;

    // 构造函数
    public Student(int id, String name, int age) throws InvalidAgeException {
        this.id = id;
        this.name = name;
        if (age < 12 || age > 18) {
            throw new InvalidAgeException("年龄不合适：" + age);
        }
        this.age = age;
    }
}

// 测试类
public class TestStudent {
    public static void main(String[] args) {
        try {
            // 模拟录入自己的学号、姓名、年龄为20
            Student student = new Student(123456, "何老师", 20);
        } catch (InvalidAgeException e) {
            System.out.println("捕获到异常：" + e.getMessage());
        }
    }
}